/*
 * Section.java
 *
 * Created on 28. Januar 2007, 21:29
 *
 * Copyright (c) 2007 Daniel Gronau
 *
 * This file is part of KanjiTori.
 *
 * KanjiTori is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * KanjiTori is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

package kanjitori.lesson;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * This class encapsulates a group of entries, subdividing a lesson.
 * @author Pirx
 */
public class Section implements Iterable<Entry> {
    
    private String name;
    private List<Entry> list;
    private boolean included = true;
    
    /**
     * Creates a new instance of section
     * @param name The name of the section. Spaces should be avoided.
     */
    public Section(String name) {
        this(name, new ArrayList<Entry>());
    }
    
    /**
     * Creates a new instance of section
     * @param name The name of the section. Spaces should be avoided.
     * @param list The list of entries
     */
    public Section(String name, List<Entry> list) {
        this.name = name;
        this.list = list;
    }
    
    /**
     * Getter for the name.
     * @return The name of the Section
     */
    public String getName() {
        return name;
    }
    
    /**
     * Adds an Entry to the Entry list.
     * @param entry The Entry which should be added.
     */
    public void addEntry(Entry entry) {
        list.add(entry);
    }
    
    /**
     * Number of Entries
     * @return The number of Entries.
     */
    public int size() {
        return list.size();
    }
    
    /**
     * Getter for an Entry.
     * @param index The index of the Entry.
     * @return The Entry at the specified position.
     */
    public Entry getEntry(int index) {
        return list.get(index);
    }

    /**
     * Implements the Iterable&lt;Entry&gt; interface.
     * @return The iterator of the Entry list.
     */
    public Iterator<Entry> iterator() {
        return list.iterator();
    }

    /**
     * Getter for the "included" property. If true,  the section 
     * will be used if the lesson is loaded.
     * @return true if this section will be used.
     */
    public boolean isIncluded() {
        return included;
    }

    /**
     * Setter for the "included" property. If true,  the section 
     * will be used if the lesson is loaded.
     * @param included If true, this section will be used.
     */
    public void setIncluded(boolean included) {
        this.included = included;
    }
    
    /**
     * Getter for the entry list.
     * @return the list of entries.
     */
    public List<Entry> getEntries() {
        return list;
    }
    
}
